package com.itcam.cm.manager.service.impl;

import com.itcam.cm.common.log.annotation.Log;
import com.itcam.cm.manager.mapper.BrandMapper;
import com.itcam.cm.manager.service.BrandService;
import com.itcam.cm.model.entity.product.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper ;

    // @Log(title = "商标分页查询", businessType = 0)
    @Override
    public PageInfo<Brand> findByPage(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Brand> brandList = brandMapper.findByPage() ;
        System.out.println("商标分页查询：brandList = " + brandList);
        // int i = 1/0;
        return new PageInfo(brandList);
    }

    @Transactional // 保存商标
    @Log(title = "商标保存", businessType = 1)// 保存日志
    @Override
    public void save(Brand brand) {
        System.out.println("记录相关信息到mysql数据库");
        brandMapper.save(brand) ;
        // int i = 1/0;
    }

    @Override
    public void updateById(Brand brand) {
        brandMapper.updateById(brand) ;
    }

    @Override
    public void deleteById(Long id) {
        brandMapper.deleteById(id) ;
    }

    @Override
    public List<Brand> findAll() {
        List<Brand> brands = brandMapper.selectAll();
        return brands;
    }
}